
import { PAGECODE, AREA, BUTTONID } from '../../constance';
import { getListDisableHotKeyBtn } from '../../tool/hotKeysUtil';
import { buttonClick } from '../btnClicks';
import { buttonControl } from '../viewControl/buttonControl';
import { getLangByResId } from '../../tool/multiLangUtil';
import { fiterAppPermissionOrg, fiterLrzxOrg } from '../../../../common/util/fiterUtils';

export default function(props) {
        props.createUIDom(
                {
                        pagecode: PAGECODE.listPagecode,
                },
                data => {
                        if (data) {
                                if (data.button) {
                                        let button = data.button;
                                        props.button.setButtons(button);
                                        props.button.setPopContent(
                                                BUTTONID.Delete,
                                                getLangByResId(this, '4001PUBMESSAGE-0000012')
                                        ); /* 国际化处理： 确定要删除吗？*/
                                        buttonControl(props);
                                        // 刷新按钮
                                        // let cacheData = getDefData(DATASOURCECACHE.dataSourceListCacheKey, DEFCACHEKEY.queryCacheKey);
                                        // props.button.setDisabled(BUTTONID.Refresh, cacheData ? false : true);
                                }
                                if (data.template) {
                                        let meta = data.template;
                                        modifierMeta.call(this, props, meta);
                                        props.meta.setMeta(meta);
                                }
                        }
                }
        );
}

function modifierMeta(props, meta) {
        props.meta.setMeta(meta);
        //查询区参照过滤
        meta[AREA.searchId].items.map((item) => {
                if (item.attrcode === 'pk_org') { //财务组织过滤
                        fiterAppPermissionOrg(props, AREA.searchId, item.attrcode, true);
                }
                else if (item.attrcode === 'vdef1') {//利润中心（部门档案）过滤
                        fiterLrzxOrg(props, AREA.searchId, item.attrcode, true, true);
                }
        });



        //添加操作列
        meta[AREA.listTableId].items.push({
                label: getLangByResId(this, '4001PUBMESSAGE-0000006') /* 国际化处理： 操作*/,
                itemtype: 'customer',
                attrcode: 'opr',
                width: '180px',
                visible: true,
                fixed: 'right',
                render: (text, record, index) => {
                        let buttonAry = [BUTTONID.Copy];
                        let hasBlue = record['isvoucher'] && record['isvoucher'].value;
                        let hasRed = record['isflag'] && record['isflag'].value;

                        if(hasBlue || hasRed){

                        }else{
                                buttonAry.push(BUTTONID.Edit, BUTTONID.Delete)
                        }

                        return props.button.createOprationButton(buttonAry, {
                                area: AREA.listInner,
                                ignoreHotkeyCode: getListDisableHotKeyBtn(),
                                buttonLimit: 3,
                                onButtonClick: (props, key) => buttonClick.call(this, props, key, text, record, index),
                        });
                },
        });

        return meta;
}


